let multer = require("multer");

//上传图片配置信息
var storage = multer.diskStorage({
  //设置存放文件路径:没有目录就上传失败
  //   destination: function (req, file, cb) {
  //     cb(null, "uploads/");
  //   },
  destination: "uploads/", //目录无则创建
  //设置文件名
  filename: function (req, file, cb) {
    //req请求对象信息；file：上传的文件对象；cb是一个修改文件名的回调
    // console.log(req, 111);
    // console.log(file, 222);
    let filename = file.originalname; //wzj.jpg
    let arr = filename.split("."); //['wzj','jpg']
    // cb(null, file.fieldname + "-" + Date.now());
    cb(null, arr[0] + "-" + Date.now() + "." + arr[1]); //加上时间戳，避免图片被覆盖
  },
});

var upload = multer({ storage: storage });


module.exports = upload;